<?
ob_start();
session_start();
include("../conf/config.php");
include("../conf/database.php");
include("../conf/tools.php");

$curTime=getIndianDateTime();
$file_id=$_GET["file_id"];
$mode=$_GET["mode"]; 

foreach($_POST as $key => $value) { $arr_data[$key]=$value;}
foreach($arr_data as $key => $value) { $arr_data[$key]=addslashes($value); }

$arr_data["rec_status"]=1;

$target_path = "../images/files/";

if(!is_dir("../images/files")) mkdir("../images/files");

if($file_id>0){

$actual_path=$target_path . $file_id . "/";
if(!is_dir($target_path)) mkdir($target_path);
if(!is_dir($actual_path)) mkdir($actual_path);

$target_path = $target_path . basename( $_FILES['fldownload']['name']); 

if(move_uploaded_file($_FILES['fldownload']['tmp_name'],$actual_path.$_FILES['fldownload']['name'])) {

	$arr_data["filename_path"]=basename($_FILES['fldownload']['name']);
} 

$arr_data["last_updated"]=$curTime;
update_qry("bkitc_files",$arr_data,"file_id=".$file_id);


}
else{

	$arr_data["rec_created"]=$curTime;
	$file_id=insert_qry("bkitc_files",$arr_data);
	
	$actual_path=$target_path . $file_id . "/";
	if(!is_dir($target_path)) mkdir($target_path);
	if(!is_dir($actual_path)) mkdir($actual_path);
	
	
	$target_path = $target_path . basename( $_FILES['fldownload']['name']); 

	$arrInfo=array();
	if(move_uploaded_file($_FILES['fldownload']['tmp_name'],$actual_path.$_FILES['fldownload']['name'])) {

		$arr_data["last_updated"]=$curTime;
		$arr_data["filename_path"]=basename( $_FILES['fldownload']['name']);
		update_qry("bkitc_files",$arr_data,"file_id=".$file_id);

	} 

	

}



header("location:edit_file.php?mode=edit&file_id=".$file_id);
?>



